import 'api_response.dart';

/// 产品信息模型
class Product {
  final int productId;
  final String productName;
  final String productKey;
  final String productSecret;
  final int? categoryId;
  final int nodeType;
  final String protocolType;
  final int dataFormat;
  final int authenticationType;
  final String description;
  final int status;
  final String createTime;
  final String? updateTime;
  final String tenantId;

  Product({
    required this.productId,
    required this.productName,
    required this.productKey,
    required this.productSecret,
    this.categoryId,
    required this.nodeType,
    required this.protocolType,
    required this.dataFormat,
    required this.authenticationType,
    required this.description,
    required this.status,
    required this.createTime,
    this.updateTime,
    required this.tenantId,
  });

  factory Product.fromJson(Map<String, dynamic> json) {
    return Product(
      productId: json['productId'],
      productName: json['productName'],
      productKey: json['productKey'],
      productSecret: json['productSecret'] ?? '',
      categoryId: json['categoryId'],
      nodeType: json['nodeType'],
      protocolType: json['protocolType'],
      dataFormat: json['dataFormat'],
      authenticationType: json['authenticationType'],
      description: json['description'] ?? '',
      status: json['status'],
      createTime: json['createTime'] ?? '',
      updateTime: json['updateTime'],
      tenantId: json['tenantId'] ?? '',
    );
  }
}

/// 产品列表响应
class ProductListResponse {
  final int total;
  final List<Product> rows;
  final int code;
  final String msg;

  ProductListResponse({
    required this.total,
    required this.rows,
    required this.code,
    required this.msg,
  });

  factory ProductListResponse.fromJson(Map<String, dynamic> json) {
    return ProductListResponse(
      total: json['total'],
      rows: (json['rows'] as List).map((e) => Product.fromJson(e)).toList(),
      code: json['code'],
      msg: json['msg'],
    );
  }

  bool get isSuccess => code == 200;
}

/// 产品详情响应
class ProductDetailResponse extends ApiResponse<Product> {
  ProductDetailResponse({
    required int code,
    required String msg,
    Product? data,
  }) : super(code: code, msg: msg, data: data);

  factory ProductDetailResponse.fromJson(Map<String, dynamic> json) {
    return ProductDetailResponse(
      code: json['code'],
      msg: json['msg'],
      data: json['data'] != null ? Product.fromJson(json['data']) : null,
    );
  }
} 